home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / xmasspak / flat / flat.inc < prev   
Encoding:
Text File  |  1995-06-19  |  5.7 KB  |  235 lines

  1. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2. ; Version 3.4
  3. ;
  4. ; Handling-Routines for using the Flatmodel of the '386/'486
  5. ;
  6. ; This version is not ment to be spread to the public so keep it as it is
  7. ; a tribute to the ESCAPE-crew.
  8. ; Other FLAT-model routines need a HIMEM-driver to get access on the extended
  9. ; memory, this one doesn't need any HIMEM-driver.
  10. ; If you use DOS loaded HIGH in the HIGH MEMORY AREA(HMA), it doesn't matter.
  11. ; The memory-handling routines keeps a safety-buffer of 65535 bytes after the
  12. ; beginning of the extended memory.
  13. ; Why wasting 10% of the cpu-time in the protected-mode when you can use the
  14. ; whole memory in real-mode.....
  15. ;
  16. ; Done by Capella/ESCAPE in may'95
  17. ;
  18. ; CALL SET_FLATMODE - sets up the FLAT-model
  19. ; CALL FLAT_READ    - reads bytes out of the extended memory
  20. ; CALL FLAT_WRITE   - writes bytes into the extended memory
  21. ; CALL CHECK_V86    - checks for an emm-driver or something like that
  22. ;
  23. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  24.  
  25. gdtsize  =   32
  26. gdtpointer      dq ?
  27.  
  28. pmode_seg       dw 0,0,0,0
  29.  
  30.                 dw 0ffffh,0
  31.                 db 0,9ah
  32.                 dw 0
  33.                 dw 0ffffh,0
  34.  
  35.                 db 0,92h
  36.                 dw 0
  37.                 dw 0ffffh,0
  38.  
  39.                 db 0,92h
  40.                 dw 0ffffh
  41.  
  42. ;
  43. ; Generating the FLAT-Model for Real-Mode using
  44. ;
  45. proc  set_flatmode  NEAR
  46.                 
  47.                 mov ax,cs              ;get code-segment
  48.                 push ds                ;save ds-segment-pointer
  49.                 mov ds,ax              ;set code-segment to ds-pointer
  50.                 mov [cs:rmode_seg],ax    ;save code-segment
  51.  
  52.                 movzx eax,ax           ;make dword our of word
  53.                 shl eax,4              ;calculate offset-pointer
  54.                 mov ebx,eax            ;save for later calculations
  55.  
  56.                 mov [cs:pmode_seg+10],ax ;set segment-pointers in Pmode
  57.                 mov [cs:pmode_seg+18],ax ;
  58.  
  59.                 ror eax,16             ;get higher word of dword
  60.  
  61.                 mov [byte cs:pmode_seg+12],al ;set segment-pointer in pmode
  62.                 mov [byte cs:pmode_seg+20],al
  63.  
  64.                 xor eax,eax              ;make eax=0
  65.  
  66.                 mov ax,offset pmode_seg  ;get offset of pmode_seg
  67.                 add ebx,eax
  68.  
  69.                 mov [word cs:gdtpointer],gdtsize
  70.                 mov [dword cs:gdtpointer+2],ebx
  71.  
  72.                 pushf
  73.                 cli
  74.                 in  al,70h
  75.                 mov ah,al
  76.                 or al,80h
  77.                 out 70h,al
  78.                 and ah,80h
  79.                 mov ch,ah
  80.  
  81.                 lgdt [fword cs:gdtpointer]
  82.  
  83.                 mov bx,ds
  84.                 mov dx,ss
  85.                 mov eax,cr0
  86.                 or al,1
  87.                 mov cr0,eax
  88.                 
  89.                 db 0eah
  90.                 dw offset pmode
  91.                 dw 8
  92.  
  93.  
  94. pmode:          mov ax,10h
  95.                 mov ss,ax
  96.                 mov ds,ax
  97.                 mov ax,18h
  98.                 mov es,ax
  99.                 mov fs,ax
  100.                 mov gs,ax
  101.                 mov eax,cr0
  102.                 and eax,not 1
  103.                 mov cr0,eax
  104.                 
  105.                 db 0eah
  106.                 dw offset rmode
  107.                 
  108. rmode_seg         dw ?
  109.  
  110. rmode:          mov ss,dx
  111.                 mov ds,bx
  112.                 xor ax,ax
  113.                 mov es,ax
  114.                 mov fs,ax
  115.                 mov gs,ax
  116.                 in al,70h
  117.                 and al,not 128
  118.                 or al,ch
  119.                 out 70h,al
  120.                 popf
  121.                 pop ds
  122.                 ret
  123.  
  124. endp
  125.  
  126. ;
  127. ; Read out of Expanded Memory
  128. ;
  129. ; DS:DI  = destination-pointer in conventional memory
  130. ; CX     = amount of bytes to read
  131. ; GS:EAX = source-pointer in expanded memory
  132. ;
  133.  
  134. proc  flat_read  NEAR
  135.                 
  136.                 push cx   
  137.                 push eax
  138.  
  139.                 call enable_a20
  140.  
  141.                 pop eax
  142.                 pop cx
  143.                 add eax,1024*1024+0ffffh
  144.  
  145. flat_loop1:     mov bl,[gs:eax]
  146.                 mov [ds:di],bl
  147.  
  148.                 inc eax
  149.                 inc di
  150.  
  151.                 dec cx
  152.                 jnz flat_loop1
  153.                 ret
  154.  
  155. endp
  156.  
  157. ;
  158. ; Write into Expanded Memory
  159. ;
  160. ; DS:SI  = source-pointer in conventional memory
  161. ; CX     = amount of bytes to write
  162. ; GS:EAX = destination-pointer in expanded memory
  163. ;
  164.  
  165. proc  flat_write  NEAR     
  166.                 
  167.                 push cx
  168.                 push eax
  169.  
  170.                 call enable_a20
  171.  
  172.                 pop eax
  173.                 pop cx
  174.                 add eax,1024*1024+0ffffh
  175.  
  176. flat_loop2:     mov bl,[ds:si]
  177.                 mov [gs:eax],bl
  178.  
  179.                 inc si
  180.                 inc eax
  181.  
  182.                 dec cx
  183.                 jnz flat_loop2
  184.                 ret
  185.  
  186. endp
  187.  
  188. ;
  189. ; Enable the Memory Adressline 20
  190. ;
  191.  
  192. enable_a20:     cli
  193.                 
  194.                 xor cx,cx
  195. flat_loop3:     in al,64h
  196.                 and al,2
  197.                 loopnz flat_loop3
  198.  
  199.                 jnz go_back
  200.  
  201.                 mov al,0d1h
  202.                 out 64h,al
  203.  
  204.                 xor cx,cx
  205. flat_loop4:     in al,64h
  206.                 and al,2
  207.                 loopnz flat_loop4
  208.  
  209.                 jnz go_back
  210.  
  211.                 mov al,0dfh
  212.                 out 60h,al
  213.  
  214.                 xor cx,cx
  215. flat_loop5:     in al,64h
  216.                 and al,2
  217.                 loopnz flat_loop5
  218.  
  219. go_back:        ret
  220.  
  221. ;
  222. ; Check for virtual memory using like (EMM,QEMM,....)
  223. ;
  224.  
  225. v86   db 0
  226.  
  227. check_v86:      cld
  228.                 smsw ax
  229.                 test ax,1
  230.                 jnz v86_found
  231.                 ret
  232. v86_found:      mov [byte cs:v86],1
  233.                 ret
  234.  
  235.